package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description NursingProjectController
 * @Author songyu
 * @Date 2024-10-15
 */
@RestController
@Api(tags = "护理项目相关接口")
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")  String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        logger.info("分页查询护理项目列表,请求参数：name={}，status={}，pageNum={}，pageSize={}",
                name,status,pageNum,pageSize);

        //调用业务分页查询护理项目数据，返回PageResponse<NursingProjectVo>
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name,status,pageNum,pageSize);

        //返回数据
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        logger.info("新增护理项目，请求参数：{}",nursingProjectDTO);

        //调用业务进行新增护理项目操作
        nursingProjectService.add(nursingProjectDTO);

        //返回数据
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(
            @PathVariable("id") Long id) {

        logger.info("根据id查询护理项目,请求参数：{}",id);

        //调用业务获取护理项目详情 NursingProjectVo
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);

        //返回数据
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {

        logger.info("修改护理项目，请求参数：{}",nursingProjectDTO);

        //调用业务修改护理项目
        nursingProjectService.update(nursingProjectDTO);

        //返回数据
        return success();
    }

}
